﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BBPA.Admin.SYS.Goods
{
    public partial class From_Bat_Brand : FormPage
    {
        BLL.Goods bll = new BLL.Goods();
        Model.Goods model = new Model.Goods();
        //
        BLL.Pic bllPic = new BLL.Pic();
        BLL.Brand bllBrand = new BLL.Brand();
        int BrandID;
        protected void Page_Load(object sender, EventArgs e) { BrandID = DataTypePlus.requestInt(Request.QueryString["BrandID"]); }
        /// <summary>
        /// 初始化本页Model
        /// </summary>
        public override void Page_Load_DefaultModel() {  }
        /// <summary>
        /// 初始化表单
        /// </summary>
        public override void Form_Default()
        {
            cbl.DataSource = bll.GetList("BrandID=0");
            cbl.DataTextField = "Name";
            cbl.DataValueField = "id";
            cbl.DataBind();
            if (cbl.Items.Count == 0)
            {
                Master.HideSubmit();
                Response.Write("所有商品已经都设置了品牌");
            }
        }
        /// <summary>
        /// 绑定表单数据【修改时用】
        /// </summary>
        public override void Form_Bind()
        {
            
        }
        /// <summary>
        /// 提交
        /// </summary>
        public override void Form_Submit()
        {
            string GoodsIDStr="";
            foreach (ListItem item in cbl.Items)
            {
                if (item.Selected)
                {
                    if (GoodsIDStr != "") GoodsIDStr += ",";
                    GoodsIDStr += item.Value;
                }
            }
            if (GoodsIDStr != "")
            {
                Maticsoft.DBUtility.DbHelperSQL.ExecuteSql("update Goods set BrandID=" + BrandID + " where id in (" + GoodsIDStr + ")");
                //foreach (Model.Goods modelGoods in bll.GetModelList(" id in(" + GoodsIDStr + ")"))
                //{
                //    //Rank
                //    List<Model.Goods> listModelGoods = bll.GetModelList("CategoryID=" + BrandID + " order by Rank desc");
                //    if (listModelGoods != null && listModelGoods.Count > 0) modelGoods.Rank = listModelGoods[0].Rank + 1;
                //    else modelGoods.Rank = 1;
                //    //Number
                //    Model.Category modelCategory = bllCategory.GetModel(BrandID);
                //    modelGoods.Number = modelCategory.Number + modelGoods.Rank.ToString().PadLeft(4, '0');//4位
                //    bll.Update(modelGoods);
                //}
                Form_Default();
                //Master.SubmitOK();
            }
               // Master.SubmitOK();

            
        }
    }
}